package com.taptech.doufu.ui.view.userdetail

import android.content.Context
import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.widget.LinearLayout
import com.google.gson.Gson
import com.taptech.doufu.R
import com.taptech.doufu.constant.Constant
import com.taptech.doufu.model.user.ActivityBean
import com.taptech.doufu.model.user.ListItem
import com.taptech.doufu.ui.activity.PersonalNewDynamicActivity
import com.taptech.doufu.util.DiaobaoUtil
import com.taptech.doufu.util.GsonUtil
import kotlinx.android.synthetic.main.view_user_detail_activity.view.*

class UserDetailActivityView(context: Context):LinearLayout(context) {


    init {
        initView()
    }

    private fun initView() {
        val view = LayoutInflater.from(context).inflate(R.layout.view_user_detail_activity,null)
        addView(view)
    }

    fun setContentNullData() {
        tvContentNull.visibility = View.VISIBLE
        ivArrow.visibility = View.GONE
    }

    fun setData(uid:Int,data: ListItem) {
        try {
            val info = GsonUtil.parseJsonWithGson(Gson().toJson(data.data), ActivityBean::class.java)
            tvUpdateTime.text = DiaobaoUtil.seconds2TimeString(info.add_time)
            tvDesc.text = info.action
            tvContent.text = info.content
            tvFrom.text = info.source
        } catch (e: Exception) {
            e.printStackTrace()
        }
        setOnClickListener {
            val intent = Intent(context, PersonalNewDynamicActivity::class.java)
            intent.putExtra(Constant.UID, "$uid")
            context.startActivity(intent)
        }
    }
}
